package com.edu.bhu.admin.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.edu.bhu.admin.domain.CosCosmetics;
import com.edu.bhu.admin.mapper.CosCosmeticsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.bhu.admin.mapper.CosOrderDetailMapper;
import com.edu.bhu.admin.domain.CosOrderDetail;
import com.edu.bhu.admin.service.ICosOrderDetailService;
import com.edu.bhu.common.core.text.Convert;

/**
 * 订单明细Service业务层处理
 * 
 * @author wangjinao
 * @date 2022-03-17
 */
@Service
public class CosOrderDetailServiceImpl implements ICosOrderDetailService 
{
    @Autowired
    private CosOrderDetailMapper cosOrderDetailMapper;

    @Autowired
    private CosCosmeticsMapper cosCosmeticsMapper;

    /**
     * 查询订单明细
     * 
     * @param orderDetailId 订单明细主键
     * @return 订单明细
     */
    @Override
    public CosOrderDetail selectCosOrderDetailByOrderDetailId(Long orderDetailId)
    {
        return cosOrderDetailMapper.selectCosOrderDetailByOrderDetailId(orderDetailId);
    }

    /**
     * 查询订单明细列表
     * 
     * @param cosOrderDetail 订单明细
     * @return 订单明细
     */
    @Override
    public List<CosOrderDetail> selectCosOrderDetailList(CosOrderDetail cosOrderDetail)
    {
        List<CosOrderDetail> details = cosOrderDetailMapper.selectCosOrderDetailList(cosOrderDetail);
        details.stream().map(o ->{
            CosCosmetics cosmetics = cosCosmeticsMapper.selectCosCosmeticsByCosId(o.getCosId());
            o.setCosmetics(cosmetics);
            return o;
        }).collect(Collectors.toList());
        return details;
    }

    /**
     * 新增订单明细
     * 
     * @param cosOrderDetail 订单明细
     * @return 结果
     */
    @Override
    public int insertCosOrderDetail(CosOrderDetail cosOrderDetail)
    {
        return cosOrderDetailMapper.insertCosOrderDetail(cosOrderDetail);
    }

    /**
     * 修改订单明细
     * 
     * @param cosOrderDetail 订单明细
     * @return 结果
     */
    @Override
    public int updateCosOrderDetail(CosOrderDetail cosOrderDetail)
    {
        return cosOrderDetailMapper.updateCosOrderDetail(cosOrderDetail);
    }

    /**
     * 批量删除订单明细
     * 
     * @param orderDetailIds 需要删除的订单明细主键
     * @return 结果
     */
    @Override
    public int deleteCosOrderDetailByOrderDetailIds(String orderDetailIds)
    {
        return cosOrderDetailMapper.deleteCosOrderDetailByOrderDetailIds(Convert.toStrArray(orderDetailIds));
    }

    /**
     * 删除订单明细信息
     * 
     * @param orderDetailId 订单明细主键
     * @return 结果
     */
    @Override
    public int deleteCosOrderDetailByOrderDetailId(Long orderDetailId)
    {
        return cosOrderDetailMapper.deleteCosOrderDetailByOrderDetailId(orderDetailId);
    }
}
